//
//  Labs_DidMovetoParent_A_DemoVC.swift
//  APSwift
//
//  Created by jianbo.pei on 2022/9/9.
//

import UIKit

class Labs_DidMovetoParent_A_DemoVC: Labs_DidMovetoParent_Base_DemoVC {

    override func viewDidLoad() {
        super.viewDidLoad()
        debugPrint("A viewDidLoad")

        // Do any additional setup after loading the view.
        view.backgroundColor = .white

        _ = UIButton(type: .custom).then({ make in
            view.addSubview(make)
            make.snp.makeConstraints { make in
                make.size.equalTo(CGSize(width: 200, height: 60))
                make.center.equalToSuperview()
            }
            make.backgroundColor = .purple
            make.setTitle("跳转到B", for: .normal)
            make.setTitleColor(.white, for: .normal)
            make.addTarget(self, action: #selector(pushToB), for: .touchUpInside)
        })
        
        labs_pushCompletion = {
            debugPrint("A labs_pushCompletion")
        }
        
        labs_popCompletion = {
            debugPrint("A labs_popCompletion")
        }
        
        pushCompletion = {
            debugPrint("A pushCompletion")
        }
        
        popCompletion = {
            debugPrint("A popCompletion")
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        debugPrint("A viewWillAppear")
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        debugPrint("A viewDidAppear")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        debugPrint("A viewWillDisappear")
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        debugPrint("A viewDidDisappear")
    }
    
    @objc private func pushToB() {
        debugPrint("\(#function)")
        let bVC = Labs_DidMovetoParent_B_DemoVC()
        bVC.labs_pushCompletion = {
            debugPrint("B labs_pushCompletion")
        }
        
        bVC.labs_popCompletion = {
            debugPrint("B labs_popCompletion")
        }
        
        bVC.pushCompletion = {
            debugPrint("B pushCompletion")
        }
        
        bVC.popCompletion = {
            debugPrint("B popCompletion")
        }
        
        isRemoveAfterPushed = true

        navigationController?.pushViewController(bVC, animated: true)
    }
    
    override func willMove(toParent parent: UIViewController?) {
        super.willMove(toParent: parent)
        debugPrint("A willMove | parent is \(String(describing: parent))")
    }
    
    override func didMove(toParent parent: UIViewController?) {
        super.didMove(toParent: parent)
        debugPrint("A didMove | parent is \(String(describing: parent))")
    }
}

/**
 /// list push A，打印信息：
 "A viewDidLoad"
 "A willMove | parent is Optional(<UINavigationController: 0x147019800>)"
 "A viewWillAppear"
 "A viewDidAppear"
 "A labs_pushCompletion"
 "A pushCompletion"
 "A didMove | parent is Optional(<UINavigationController: 0x147019800>)"
 
"A viewDidLoad"
"A willMove | parent is Optional(<UINavigationController: 0x140809400>)"
"A viewWillAppear"
"A viewDidAppear"
"A didMove | parent is Optional(<UINavigationController: 0x140809400>)"
"pushToB()"
"B willMove | parent is Optional(<UINavigationController: 0x140809400>)"
"B viewDidLoad"
"A viewWillDisappear"
"B viewWillAppear"
"A viewDidDisappear"
"B viewDidAppear"
"B didMove | parent is Optional(<UINavigationController: 0x140809400>)"
*/
